package com.flying.test;

import java.util.function.Consumer;

import static java.util.Objects.requireNonNull;

@FunctionalInterface
public interface ThrowingConsumer<T> {
    void accept(T t) throws Exception;

    @SuppressWarnings("unchecked")
    static <E extends Exception> void sneakyThrow(Exception e) throws E {
        throw (E) e;
    }

    static <T> Consumer<T> unchecked(ThrowingConsumer<T> c) {
        requireNonNull(c);
        return t -> {
            try {
                c.accept(t);
            } catch (Exception e) {
                ThrowingConsumer.sneakyThrow(e);
            }
        };
    }
}